package student

import (
	"data/config"
	"public/mysqldb"
	"public/tools"
)

//获取招生老师下的全部学生
func GetStudentsRetStatus(teacher string) (wait, pass, refuse []*StudentInfo) {
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	orm.Table("student_info_view").Where("teacher = ? and status = 0", teacher).Find(&wait)   //待审核
	orm.Table("student_info_view").Where("teacher = ? and status = 1", teacher).Find(&pass)   //已通过
	orm.Table("student_info_view").Where("teacher = ? and status = 2", teacher).Find(&refuse) //未通过

	if len(wait) > 0 {
		for _, v := range wait {
			var tmp []FamilyInfo
			// json.Unmarshal([]byte(v.Family_info), &tmp)
			tools.GetJsonObj(v.Family_info, &tmp)
			v.Family = tmp
		}
	}

	if len(pass) > 0 {
		for _, v := range pass {
			var tmp []FamilyInfo
			tools.GetJsonObj(v.Family_info, &tmp)
			v.Family = tmp
		}
	}
	if len(refuse) > 0 {
		for _, v := range refuse {
			var tmp []FamilyInfo
			tools.GetJsonObj(v.Family_info, &tmp)
			v.Family = tmp
		}
	}
	//var  wait_tmp []Student_info_tbl
	//获取的时候指定外键
	// orm.Where("teacher = ? and status = 0", teacher).Find(&wait_tmp)
	// for i := 0; i < len(wait_tmp); i++ {
	// 	orm.Model(&wait_tmp[i]).Related(&wait_tmp[i].User_info_tbl, "User_info_id")
	// }

	return
}
